fix(runtime): display proper error when throwing in event handlers#32663
Merged
bartlomieju merged 2 commits intomainfrom Mar 12, 2026
Merged
fix(runtime): display proper error when throwing in event handlers#32663bartlomieju merged 2 commits intomainfrom
bartlomieju merged 2 commits intomainfrom
Conversation
When throwing in `unload`, `beforeunload`, `load`, or process exit/beforeExit event handlers, Deno displayed "Uncaught null" instead of the actual error message and stack trace. The root cause: when an event listener throws, the JS-side `reportException` calls `op_dispatch_exception` which stores the real exception in `ExceptionState` and terminates execution. The Rust-side event dispatch functions then checked `tc_scope.exception()` which returned the termination exception (null), not the stored one. Using `exception_to_err` instead properly retrieves the dispatched exception. Closes #29087 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
kajukitli
approved these changes
Mar 12, 2026
Contributor
kajukitli
left a comment
There was a problem hiding this comment.
lgtm
using exception_to_err() here is the right fix. these call sites were bypassing the existing dispatched-exception handling and going straight to tc_scope.exception(), so once termination had swapped in the null-ish termination exception they lost the real error.
the new tests for load / beforeunload / unload cover the browser-style event cases well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
"Uncaught null"being displayed instead of the actual error when throwing inunload,beforeunload,load, or processexit/beforeExitevent handlersreportExceptionin JS callsop_dispatch_exceptionwhich stores the real exception inExceptionStateand terminates execution. The Rust-side dispatch functions then checkedtc_scope.exception()which returnednull(the termination exception) instead of the stored oneexception_to_errwhich properly checksExceptionStatefor a dispatched exception before falling back totc_scope.exception()Before:
After:
Closes #29087